home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_enscript.idb / usr / freeware / share / enscript / hl / cpp.st.z / cpp.st
Encoding:
Text File  |  2002-04-08  |  2.7 KB  |  120 lines

  1. /**
  2.  * Name: cpp
  3.  * Description: C++ programming language.
  4.  * Author: Markku Rossi <mtr@iki.fi>
  5.  */
  6.  
  7. cpp_type_re =
  8. /* Types.
  9.    (build-re '(auto bool char class complex const double enum extern
  10.    float friend inline int long private protected public register
  11.    short signed static struct template typedef union unsigned virtual
  12.    void volatile))
  13.   */
  14.   /\b(auto|bool|c(har|lass|o(mplex|nst))|double|e(num|xtern)|f(loat|riend)\
  15. |in(line|t)|long|p(r(ivate|otected)|ublic)|register\
  16. |s(hort|igned|t(atic|ruct))|t(emplate|ypedef)|un(ion|signed)\
  17. |v(irtual|o(id|latile)))\b/;
  18.  
  19. /*
  20.  * We inherit the C++ state from the C state.  This gives us all the
  21.  * defaults, etc.  All we have to do here is to overwrite things that
  22.  * are not implemented, or are broken.
  23.  */
  24. state cpp extends c
  25. {
  26.   BEGIN {
  27.     /* See `c.st' for the comments on this one. */
  28.     type_re = cpp_type_re;
  29.   }
  30.  
  31.   /* One line comments. */
  32.   /\/\// {
  33.     comment_face (true);
  34.     language_print ($0);
  35.     call (eat_one_line);
  36.     comment_face (false);
  37.   }
  38.  
  39.   /* Keywords; those missing from C, but not types, goto, or case
  40.      (build-re '(asm catch delete new operator overload this throw try))
  41.   */
  42.   /\b(asm|catch|delete|new|o(perator|verload)|t(h(is|row)|ry))\b/ {
  43.     keyword_face (true);
  44.     language_print ($0);
  45.     keyword_face (false);
  46.   }
  47.  
  48.   /* Types. */
  49.   cpp_type_re {
  50.     type_face (true);
  51.     language_print ($0);
  52.     type_face (false);
  53.   }
  54.  
  55.   /* Remove false labels. */
  56.   /[a-zA-Z0-9_]+::/ {
  57.     language_print ($0);
  58.   }
  59.  
  60.   /* Labels.  Emacs accepts also bare numbers. */
  61.   /^([ \t]*)([a-zA-Z0-9_]+)(:)/ {
  62.     language_print ($1);
  63.  
  64.     if (strcmp ($2, "public") == 0
  65.     || strcmp ($2, "private") == 0
  66.     || strcmp ($2, "protected") == 0)
  67.       {
  68.     /* These use the `type' face. */
  69.     type_face (true);
  70.     language_print ($2);
  71.     type_face (false);
  72.       }
  73.     else
  74.       {
  75.     reference_face (true);
  76.     language_print ($2);
  77.     reference_face (false);
  78.       }
  79.  
  80.     language_print ($3);
  81.   }
  82.  
  83.   /*
  84.    * Function definitions, but only if you code with the one and only
  85.    * usable indentation style (GNU).
  86.    */
  87.   /^([a-zA-Z_][a-zA-Z_0-9:~]*)([ \t]*\()/ {
  88.     function_name_face (true);
  89.     language_print ($1);
  90.     function_name_face (false);
  91.  
  92.     language_print ($2);
  93.   }
  94.  
  95.   /* Function definitions and prototypes for other (loser) coding styles. */
  96.   /^([A-Za-z][a-zA-Z0-9_\&\* ]+)([ \*])([a-zA-Z_][a-zA-Z_0-9:~]*)([ \t]*\()/ {
  97.     garbage = $1;
  98.     middle_garbage = $2;
  99.     function_name = $3;
  100.     tail_garbage = $4;
  101.  
  102.     highlight_types (garbage, cpp_type_re);
  103.  
  104.     language_print (middle_garbage);
  105.  
  106.     function_name_face (true);
  107.     language_print (function_name);
  108.     function_name_face (false);
  109.  
  110.     language_print (tail_garbage);
  111.   }
  112. }
  113.  
  114.  
  115. /*
  116. Local variables:
  117. mode: c
  118. End:
  119. */
  120.